package com.gx.controller.page;

import com.alibaba.fastjson.JSONArray;
import com.gx.base.CurrentUser;
import com.gx.constant.ShiroConstants;
import com.gx.core.shiro.utils.ShiroUtils;
import com.gx.service.api.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/")
public class HomeController {

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("/index*")
    public ModelAndView index(Model model) {
        ModelAndView mv = new ModelAndView("/main/main");
        JSONArray menuJson = sysMenuService.getMenuJsonList();
        CurrentUser currentUser = ShiroUtils.getCurrentUser();
        mv.addObject("menus", menuJson);
        mv.addObject(ShiroConstants.CURRENT_USER, currentUser);
        return mv;
    }
}
